package uk.ac.glasgow.demosocs.tests;

import static org.junit.Assert.*;

import java.util.Date;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import uk.ac.glasgow.demosocs.VotingSystem;
import uk.ac.glasgow.demosocs.impl.VotingSystemStub;


public class NF5Elections {

	private VotingSystem testVS;

	@Before
	public void setUp() throws Exception {
		testVS = new VotingSystemStub();
		testVS.setCurrentUser("admin", "p");
		testVS.createElection("oldE", "Simple_Plurality");
		testVS.editElection(new Date(), new Date(), new Date(), "Level_3");
	}

	@After
	public void tearDown() throws Exception {
		testVS = null;
	}

	@Test
	/** creates a new election 
	 * if successful then new current Election will be 
	 * different to the old current election
	 */
	public void test5ConcurrentElections() {
	
		String name;

		int runningcount = 0;

		for (int i = 0; i < 5; i++) {
			
			name = "test" + i;
			testVS.createElection(name, "Simple_Plurality");
		
			Date current = new Date();
		
			testVS.editElection(current, current, current, "Level_3");
		
			String ID = testVS.getCurrentElection().getEID();
			testVS.setCurrentElection(ID);

			if (testVS.getCurrentElection() != null)
				runningcount++;
		}

		assertEquals(5, runningcount);
	}


}
